
package org.darcy.entity.work;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import org.darcy.framework.constant.SysConstant;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

@Schema(description="Work: 工作项")
@TableName(value = "work_instance")
@Getter
@Setter
@Slf4j
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WorkInstance implements Serializable, Cloneable {

	private static final long serialVersionUID = 1L;

	@Schema(description = "")
	@TableId(type = IdType.AUTO)
	private Integer id;

	@Schema(description = "表单类型")
	@TableField(value = "`form_type`")
	private String formType;

	@Schema(description = "表单id")
	@TableField(value = "`form_id`")
	private Integer formId;
	
	@Schema(description = "分组id=合同id")
	@TableField(value = "`group_id`")
	private Integer groupId;

	@Schema(description = "标题")
	@TableField(value = "`title`")
	private String title;

	@Schema(description = "摘要")
	@TableField(value = "`summary`")
	private String summary;
	
	@Schema(description = "发起人")
	@TableField(value = "`operator_name`")
	private String operatorName;

	@Schema(description = "发起时间")
	@TableField(value = "`start_time`")
	private Date startTime;

	@Schema(description = "结束时间")
	@TableField(value = "`stop_time`")
	private Date stopTime;

	@Schema(description = "审批状态，0：草稿；9：已抄送；10：审批中；20：已拒绝；30：已撤销；100：已通过；)")
	@TableField(value = "`status`")
	private Integer status;

	@Schema(description = "创建时间")
	@TableField(value = "`create_time`")
	private Date createTime;

	@Schema(description = "更新时间")
	@TableField(value = "`update_time`")
	private Date updateTime;

	@Schema(description = "删除标识0：删除；1：存在")
	@TableField(value = "`del_flag`")
	private Integer delFlag;

	///

	@Schema(description = "流程状态名称")
	@TableField(exist = false)
	private String statusName;

	@Schema(description = "所有任务")
	@TableField(exist = false)
	private List<WorkTask> allTask;

	@Schema(description = "主干任务，不包含抄送")
	@TableField(exist = false)
	private List<WorkTask> mainTask;

	@Schema(description = "当前任务")
	@TableField(exist = false)
	private WorkTask task;

	@Schema(description = "业务数据")
	@TableField(exist = false)
	private Object businessData;

	// 查询参数

	@Schema(description = "用户id")
	@TableField(exist = false)
	private Integer uid;

	@Schema(description = "任务类型：1：待处理；2：已处理；3：已提交；4：抄送我；5：草稿")
	@TableField(exist = false)
	private Integer taskType;

	@Schema(description = "查询关键字")
	@TableField(exist = false)
	protected String keyword;

	@Schema(description = "查询开始时间")
	@TableField(exist = false)
	private Date queryBegin;

	@Schema(description = "查询结束时间")
	@TableField(exist = false)
	private Date queryEnd;

	/**
	 * 获取流程的状态名称
	 */
	public String fetchStatusName() {
		if (status == null) {
			return "未知状态";
		}
		switch (status) {
		case SysConstant.FlowStatus.STATUS0_DRAFT:
			return "草稿";
		case SysConstant.FlowStatus.STATUS9_CC:
			return "已抄送";
		case SysConstant.FlowStatus.STATUS10_APPROVING:
			return "审批中";
		case SysConstant.FlowStatus.STATUS20_REJECT:
			return "已拒绝";
		case SysConstant.FlowStatus.STATUS30_CANCEL:
			return "已撤销";
		case SysConstant.FlowStatus.STATUS100_APPROVED:
			return "已通过";
		default:
			break;
		}
		return "未知状态";
	}

	public WorkInstance clone() {
		WorkInstance task = null;
		try {
			task = (WorkInstance) super.clone();
		} catch (CloneNotSupportedException e) {
			log.error("WorkTask clone 失败", e);
		}
		return task;
	}

}
